/**
 * 
 */
package com.jysz.certificate.web.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jysz.certificate.action.AbstractBaseAction;
import com.jysz.certificate.service.CommonService;

/**
 * @author kacarich email:javaengine@outlook.com
 * 
 */
@Controller
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Namespace("/common")
public class CommonAction extends AbstractBaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String classType;
	private Long entityId;
	private String keyword;
	private String displayFields;
	private String filterSql;
	
	@Resource
	private CommonService commonService;
	
	@SuppressWarnings("rawtypes")
	@Action("autocomplete")
	public String autocomplete() {
		//FIXED:不支持中文拼音检索
		List list = commonService.findAutocompleteEntitys(classType, keyword, displayFields, filterSql);
		if(list == null ){
			this.setJsonText("[]");
		}else{
//			Gson gson = new Gson();
			Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
			this.setJsonText(gson.toJson(list).toString());
//			this.setJsonText(JSONObject.fromObject(list).toString());
		}
		
		return JSON_PAGE;
	}



	public String getClassType() {
		return classType;
	}

	public void setClassType(String classType) {
		this.classType = classType;
	}

	public Long getEntityId() {
		return entityId;
	}

	public void setEntityId(Long entityId) {
		this.entityId = entityId;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public String getDisplayFields() {
		return displayFields;
	}

	public void setDisplayFields(String displayFields) {
		this.displayFields = displayFields;
	}



	public String getFilterSql() {
		return filterSql;
	}



	public void setFilterSql(String filterSql) {
		this.filterSql = filterSql;
	}
	
	
}
